package com.javaweb.constant;

import java.util.regex.Pattern;

import com.javaweb.web.controller.AllOpenController;

/**
 * 系统常量类
 * @author tank2140896
 */
public final class SystemConstant {
	
	/**
	 * 系统编号
	 * <p>
	 * 每个系统都应该设置不同的值
	 */
	public static final String SYSTEM_NO = "1";
	
	/**
	 * 系统应用key的前缀
	 */
	public static final String APP_KEY_PREFIX = "app_";
	
	/**
	 * 项目的根包
	 */
	public static final String BASE_PACKAGE = "com.javaweb";
	
	/**
	 * 权限拦截/web下面的所有请求
	 */
	public static final String WEB_PERMISSION_INTERCEPTOR_PATTERNS = "/web/**";
	
	/**
	 * 默认全局CONTROLLER对应的包
	 */
	public static final String DEFAULT_GLOBAL_CONTROLLER_PACKAGE = "com.javaweb.web.controller";
	
	/**
	 * 默认全局CONTROLLER对应的路径
	 */
	public static final String DEFAULT_GLOBAL_CONTROLLER_PATH = "com/javaweb/web/controller";

	/**
	 * 所有url的正则通配
	 */
	public static final String URL_ALL_PATTERN = "/*";

    /**
     * 最佳路径匹配
     */
	public static final String BEST_MATCHING_PATTERN = "org.springframework.web.servlet.HandlerMapping.bestMatchingPattern";
	
	/**
	 * environment的bean名称
	 */
	public static final String ENVIRONMENT = "environment";
	
	/**
	 * 接口请求获取的属性名称
	 */
	public static final String REQUEST_URL_CHAIN_ATTRIBUTE_NAME = "interfaces";

	/**
	 * HTTP请求方法之OPTIONS
	 */
	public static final String HTTP_REQUEST_METHOD_OPTIONS = "OPTIONS";
	
	/** 数组、集合定义为final依然是可以被修改的，所以采用下面的写法（数组：数组.clone()） */
	//private static final List<Module> E_M_L = new ArrayList<>();
	//public static final List<Module> EMPTY_MODULE_LSIT = Collections.unmodifiableList(E_M_L);
	//或
	//public static final List<Module> EMPTY_MODULE_LSIT = Collections.emptyList();
	
	/* login start */
	public final class LoginConstant {
		
		/**
		 * 验证类型
		 * <p>
		 * 1：二维码；2：图形验证码；3：短信验证码
		 */
		public static final Pattern VERIFY_PATTERN = Pattern.compile("[123]");
		
		/**
		 * 验证密钥
		 */
		public static final String VERIFY_SECRET = ":!_5<`v)D;EKHENx[`Jm84~s";
		
		/**
		 * 用户账号校验正则
		 */
		public static final String USERNAME_REGEXP = "[0-9A-Za-z]{3,20}";
		
		/**
		 * 用户密码校验正则
		 */
		public static final String PASSWORD_REGEXP = "([0-9]|[A-Z]|[a-z]|[<>~!@#%&_-]){3,20}";
		
		/**
		 * 用户密码预编译正则
		 * @see AllOpenController#passwordCheck
		 */
		public static final Pattern PASSWORD_REGEXP_PATTERN = Pattern.compile(PASSWORD_REGEXP);
		
		/**
		 * 默认的密码（已经过SHA-256加密）默认为abcd1234
		 */
		public static final String DEFAULT_PASSWORD = "e9cee71ab932fde863338d08be4de9dfe39ea049bdafb342ce659ec5450b69ae";
		
		/**
		 * token的aes加密密钥，默认采用SecretUtil.defaultGenRandomPass(24)生成
		 * <p>
		 * 这里固定写死，如果动态的话相当于服务器每次重启都不一样，但是分布式部署时需要考虑值的统一
		 */
		public static final String TOKEN_AES_KEY = "+6'V^QgAEiV!GmvL&MkL6~fh";

		/**
		 * token的key值的前缀
		 */
		public static final String TOKEN_KEY_PREFIX = "tokenKey" + CommonConstant.COLON;
		
		/**
		 * 图形验证码的key值的前缀
		 */
		public static final String CAPTCHA_KEY_PREFIX = "captchaKey" + CommonConstant.COLON;
	
	}
	/* login end */
	
	
	/* 多数据源 start */
	public final class DataSourceConstant {
		
		/**
		 * 数据源1的key值
		 */
		public static final String DATA_SOURCE_KEY_1 = "mysql_d1";
		
		/**
		 * 数据源1的包
		 */
		public static final String DATA_SOURCE_PACKAGE_DS1 = "com.javaweb.web.dao.ds1";
		
		/**
		 * 数据源1的sqlSessionFactory
		 */
		public static final String DATA_SOURCE_SQL_SESSION_FACTORY_1 = "sqlSessionFactory1";
		
		/**
		 * 数据源1的mysqlJdbcTemplate
		 */
		public static final String DATA_SOURCE_D1_JDBCTEMPLATE = "mysql_d1_JdbcTemplate";
		
		/**
		 * 数据源2的key值
		 */
		public static final String DATA_SOURCE_KEY_2 = "mysql_d2";
		
		/**
		 * 数据源2的包
		 */
		public static final String DATA_SOURCE_PACKAGE_DS2 = "com.javaweb.web.dao.ds2";
		
		/**
		 * 数据源2的sqlSessionFactory
		 */
		public static final String DATA_SOURCE_SQL_SESSION_FACTORY_2 = "sqlSessionFactory2";
		
		/**
		 * 数据源2的mysqlJdbcTemplate
		 */
		public static final String DATA_SOURCE_D2_JDBCTEMPLATE = "mysql_d2_JdbcTemplate";
		
	}
	/* 多数据源 end */
	
	/* redis start */
	public final class RedisConstant {
		
		/**
		 * redisTemplate的bean名称
		 */
		public static final String REDIS_TEMPLATE = "redisTemplate";
		
		/**
		 * redis接口调用次数统计的key值
		 */
		public static final String REDIS_INTERFACE_COUNT_KEY = "redis_interface_count_key";
		
		/**
		 * redis配置信息订阅的主题名称
		 */
	    public static final String REDIS_CONFIG_TOPIC = "CONFIG";
	    
		/**
		 * redis字典信息订阅的主题名称
		 */
	    public static final String REDIS_DICTIONARY_TOPIC = "DICTIONARY";
	    
		/**
		 * redis接口信息订阅的主题名称
		 */
	    public static final String REDIS_INTERFACES_TOPIC = "INTERFACES";

	}
	/* redis end */
	
	/* admin start */
	public final class AdminConstant {
		
		/**
		 * admin的用户ID特殊化为-1，该值不建议修改
		 */
		public static final String ADMIN_USER_ID = "-1";
		
		/**
		 * admin的账号默认为admin
		 */
		public static final String ADMIN_USER_NAME = "admin";
		
		/**
		 * admin的密码（已经过SHA-256加密）默认为admin
		 */
		public static final String ADMIN_PASSWORD = "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918";
		
	}
	/* admin end */
	
	/* head start */
	public final class HeadConstant {
		
		/**
		 * header-userid的key值
		 */
		public static final String HEAD_USERID = "userId";
		
		/**
		 * header-token的key值
		 */
		public static final String HEAD_TOKEN = "token";
		
		/**
		 * header-alias的key值
		 */
		public static final String HEAD_ALIAS = "alias";
		
		/**
		 * response的header
		 */
		public static final String RESPONSE_HEADER_URL_PATTERN = "Url-Pattern";

		/**
		 * response的header
		 */
		public static final String RESPONSE_HEADER_NONCE = "nonce";
		
	}
	/* head end */
	
	/* 定时任务 start */
	public final class ScheduledTaskConstant {
		
		/**
		 * 默认分布式定时任务切点
		 * execution(* *.*(..)) && @annotation(com.javaweb.annotation.task.DistributedTimedTask)
		 * execution(* com.javaweb.task.*.*(..)) && @annotation(com.javaweb.annotation.task.DistributedTimedTask)
		 */
		public static final String DEFAULT_DISTRIBUTED_TIMED_TASK_POINT_CUT = "@annotation(com.javaweb.annotation.task.DistributedTimedTask)";
		
		/**
		 * 分布式定时任务锁的key值
		 */
		public static final String DISTRIBUTED_TIMED_TASK_KEY = "LOCK";
		
	}
	/* 定时任务 end */
	
	/* 日志 start */
	public final class LogConstant {
		
		/**
		 * 默认日志记录切点
		 */
		public static final String DEFAULT_LOG_POINT_CUT = "execution(* com.javaweb.web.controller..*.*(..))";
		
	}
	/* 日志 end */
	
	/* 接口限流 start */
	public final class InterfaceLimit {
		
		/**
		 * /actuator             -> 监控
		 * /ws/onlineChat        -> websocket在线聊天室
		 * /ws/onlineBroadcast   -> websocket在线广播
		 */
		public static final Pattern EXCLUSIVE_URL_PATTERN = Pattern.compile("(/actuator.*)||(/ws/onlineChat)||(/ws/onlineBroadcast)");
		
	}
	/* 接口限流 end */

}
